package ${basePackage}.cli.command;

import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSONUtil;
import ${basePackage}.generator.ExecutorFileGenerator;
import ${basePackage}.model.Meta;
import lombok.Data;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

import java.util.concurrent.Callable;

/**
* @author ${author!''}
* @version 1.1.0
*/
@Command(name = "json-generate", description = "读取 json 文件生成代码", mixinStandardHelpOptions = true)
@Data
public class JsonGenerateCommand implements Callable<Integer> {

    @Option(names = {"-f", "--file"}, arity = "0..1", description = "json 文件路径", interactive = true, echo = true)
    private String filePath;

    public Integer call() throws Exception {
        // 读取 json 文件，转换为数据模型
        String jsonStr = FileUtil.readUtf8String(filePath);
        Meta meta = JSONUtil.toBean(jsonStr, Meta.class);
        ExecutorFileGenerator.generator(meta);
        return 0;
    }
}
